package cn.pli.bike.ui;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.framemodule.BaseApp.BaseApp;
import com.framemodule.utils.CommonUtils;

import java.util.IllegalFormatCodePointException;
import java.util.List;

import cn.bingoogolapple.androidcommon.adapter.BGARecyclerViewAdapter;
import cn.bingoogolapple.androidcommon.adapter.BGARecyclerViewHolder;
import cn.bingoogolapple.androidcommon.adapter.BGAViewHolderHelper;
import cn.pli.bike.App;
import cn.pli.bike.R;
import cn.pli.bike.bean.ProblemBean;
import cn.pli.bike.bean.UserInfoSetBean;

/**
 * Created by shangdongzhou on 2017/11/19.
 */

public class CallCenterMainAdapter extends BGARecyclerViewAdapter<List<ProblemBean>> {
    private static final int SERVER_SELF = R.layout.item_call_center_self_service;            //自助服务
    private static final int COMMON_PROBLEM = R.layout.item_call_center_common_problem;       //常见问题
    private static final int CONNECT_SERVICE = R.layout.item_call_center_connect_service;     //联系客服
    private int[] layouts = {SERVER_SELF, COMMON_PROBLEM, CONNECT_SERVICE};
    private LayoutInflater mInflater;

    public CallCenterMainAdapter(RecyclerView recyclerView) {
        super(recyclerView, R.layout.item_user_info);
        mInflater = LayoutInflater.from(BaseApp.getInstance());


    }


    @Override
    protected void fillData(BGAViewHolderHelper helper, int position, List<ProblemBean> model) {
        if (position == 1) {
            RecyclerView recyclerView = helper.getView(R.id.recycler_common_main_problem);
            CommonProblemAdapter commonProblemAdapter = new CommonProblemAdapter(recyclerView);
            recyclerView.setLayoutManager(new LinearLayoutManager(App.getApp()));
            recyclerView.setAdapter(commonProblemAdapter);
            commonProblemAdapter.setData(model);

        }
    }


    @Override
    public int getItemCount() {
        return getData().size() + 2;
    }

    @Override
    public int getItemViewType(int position) {
        if (getData().size() > 0) {
            return layouts[position];
        }
        if (position == 1) {
            return layouts[2];
        } else {
            return layouts[position];
        }
    }

    @Override
    public BGARecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        BGARecyclerViewHolder viewHolder = null;
        view = mInflater.inflate(viewType, parent, false);
        viewHolder = new BGARecyclerViewHolder(this, mRecyclerView, view, mOnRVItemClickListener, mOnRVItemLongClickListener);
        viewHolder.getViewHolderHelper().setOnItemChildClickListener(mOnItemChildClickListener);
        viewHolder.getViewHolderHelper().setOnItemChildLongClickListener(mOnItemChildLongClickListener);
        setItemChildListener(viewHolder.getViewHolderHelper(), viewType);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(BGARecyclerViewHolder viewHolder, int position) {
        if (position == 1 && getData().size() > 0) {
            fillData(viewHolder.getViewHolderHelper(), position, getItem(0));
        }

    }

    @Override
    protected void setItemChildListener(BGAViewHolderHelper helper, int viewType) {
        super.setItemChildListener(helper, viewType);
        helper.setItemChildClickListener(R.id.tv_report_fault);
        helper.setItemChildClickListener(R.id.tv_report_illegal_parking);
        helper.setItemChildClickListener(R.id.tv_back_deposit);
        helper.setItemChildClickListener(R.id.tv_recharge);
        helper.setItemChildClickListener(R.id.tv_connect_service);
    }
}


